<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('素材信息列表')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body class="gray-bg">
<div class="ui-layout-west">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa icon-grid"></i> 素材分组
            </div>
            <div class="box-tools pull-right">
                <a type="button" class="btn btn-box-tool" href="#" onclick="openGroup()" title="管理素材分组"><i
                        class="fa fa-edit"></i></a>
                <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i
                        class="fa fa-chevron-up"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i
                        class="fa fa-chevron-down"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新"><i class="fa fa-refresh"></i>
                </button>
            </div>
        </div>
        <div class="ui-layout-content">
            <div id="tree" class="ztree"></div>
        </div>
    </div>
</div>
<div class="ui-layout-center">

    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li style="display:none;">
                                <p>分组id：</p>
                                <input type="text" name="groupId" id="groupId"/>
                            </li>
                            <li>
                                <p>素材名称：</p>
                                <input type="text" name="materialName"/>
                            </li>
                            <li>
                                <p>素材类型：</p>
                                <select name="materialType" th:with="type=${@dict.getType('csm_material_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                            th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="resetPre();"><i
                                        class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>
<th:block th:include="include :: select2-js"/>
<script th:inline="javascript">
    function resetPre() {
        $.form.reset();
        $("#merchantId").val($("#merchantId").val()).trigger("change");
    }

    var editFlag = [[${@permission.hasPermi('bussiness_cms:material:edit')}]];
    var removeFlag = [[${@permission.hasPermi('bussiness_cms:material:remove')}]];
    var materialTypeDatas = [[${@dict.getType('csm_material_type')}]];
    var auditStateDatas = [[${@dict.getType('cms_audit_state')}]];
    var useStateDatas = [[${@dict.getType('sms_use_state')}]];
    var prefix = ctx + "bussiness_cms/material";

    $(function () {
        var panehHidden = false;
        if ($(this).width() < 769) {
            panehHidden = true;
        }
        $('body').layout({initClosed: panehHidden, west__size: 185});
        queryMaterialGroupTree();
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "素材信息",
            sortName: "createTime",
            sortOrder: "desc",
            columns: [{
                checkbox: true
            },
                {
                    field: 'materialId',
                    title: '素材id',
                    visible: false
                },
                {
                    field: 'merchantName',
                    title: '所属商户',
                    formatter: function (value) {
                        if (!value)
                            return '系统商户';
                        return value;
                    }
                },
                {
                    field: 'materialName',
                    title: '素材名称'
                },
                {
                    field: 'groupName',
                    title: '所属分组',
                    align: 'left'
                },
                {
                    field: 'savePath',
                    title: '素材图片',
                    formatter: function (value) {
                        if (value) {
                            value = ctx + "profile" + value;
                            return "<img src='"
                                + value
                                + "' style='height: 36px;' target='_blank' tile='点击查看' onclick='$.operate.alertPic(\""
                                + value
                                + "\")'></img>";
                        }
                    }
                },
                {
                    field: 'materialType',
                    title: '素材类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(materialTypeDatas, value);
                    }
                },
                {
                    field: 'materialDescription',
                    title: '素材描述'
                },

                {
                    field: 'auditState',
                    title: '审核状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(auditStateDatas, value);
                    }
                },
                {
                    field: 'auditReason',
                    title: '审核意见'
                },
                {
                    field: 'useState',
                    title: '可用状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(useStateDatas, value);
                    }
                },
                {
                    field: 'createTime',
                    title: '创建时间'
                },
                {
                    field: 'updateTime',
                    title: '更新时间'
                }]
        };
        $.table.init(options);
    });

    $('#btnExpand').click(function () {
        $._tree.expandAll(true);
        $(this).hide();
        $('#btnCollapse').show();
    });

    $('#btnCollapse').click(function () {
        $._tree.expandAll(false);
        $(this).hide();
        $('#btnExpand').show();
    });

    $('#btnRefresh').click(function () {
        queryMaterialGroupTree();
    });

    function queryMaterialGroupTree() {
        var url = ctx + "bussiness_cms/materialgroup/treeData";
        var options = {
            url: url,
            expandLevel: 2,
            onClick: zOnClick
        };
        $.tree.init(options);

        function zOnClick(event, treeId, treeNode) {
            $("#groupId").val(treeNode.id);
            $.table.search();
        }
    }

    /* 打开分组管理 */
    function openGroup() {
        var url = ctx + "bussiness_cms/materialgroup";
        $.modal.openTab("素材组别管理", url);
    }

    function submitHandler() {
        var rows = $.table.selectFirstColumns();
        if (rows.length != 1) {
            $.modal.alertWarning("请选择一条记录");
            return;
        }
        var datas = $("#bootstrap-table").bootstrapTable('getSelections');
        var id = datas[0].materialId;
        var name = datas[0].materialName;
         var index = parent.layer.getFrameIndex(window.name);
        parent.$("#materialId").val(id);
        parent.$("#materialName").val(name);
        parent.layer.close(index);
    }
</script>
</body>
</html>